<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="java,C++," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.2" />






<meta name="description" content="linux为CentOS release 6.6 (Final)另，博客中示例使用的opencv相关见OpenCV for Linux环境">
<meta property="og:type" content="article">
<meta property="og:title" content="Linux环境下java通过JNI调用C++程序">
<meta property="og:url" content="https://my.oschina.net/u/588736/blog/2017/03/03/jni_opencv/index.html">
<meta property="og:site_name" content="晚来风">
<meta property="og:description" content="linux为CentOS release 6.6 (Final)另，博客中示例使用的opencv相关见OpenCV for Linux环境">
<meta property="og:updated_time" content="2017-03-03T03:39:36.068Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Linux环境下java通过JNI调用C++程序">
<meta name="twitter:description" content="linux为CentOS release 6.6 (Final)另，博客中示例使用的opencv相关见OpenCV for Linux环境">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="https://my.oschina.net/u/588736/blog/2017/03/03/jni_opencv/"/>


  <title> Linux环境下java通过JNI调用C++程序 | 晚来风 </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">晚来风</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">林花谢了春红，太匆匆。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Linux环境下java通过JNI调用C++程序
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2017-03-03T00:00:00+08:00" content="2017-03-03">
              2017-03-03
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/编程语言/" itemprop="url" rel="index">
                    <span itemprop="name">编程语言</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>linux为CentOS release 6.6 (Final)<br>另，博客中示例使用的opencv相关见<a href="http://gxjaha.oschina.io/2017/03/03/opencv_for_linux/" target="_blank" rel="external">OpenCV for Linux环境</a><br><a id="more"></a></p>
<h2 id="java-jni调用C-语言动态链接库的具体操作步骤"><a href="#java-jni调用C-语言动态链接库的具体操作步骤" class="headerlink" title="java jni调用C++语言动态链接库的具体操作步骤:"></a>java jni调用C++语言动态链接库的具体操作步骤:</h2><ul>
<li>创建一个Java程序（OpenCV4j.java）定义原生的C++函数。</li>
<li>用javac编译OpenCV4j.java生成OpenCV4j.class。用javah带-jni参数编译OpenCV4j.class生成OpenCV4j.h头文件，该头文件中定义了C++的函数原型。在实现C++函数的时候需要。</li>
<li>创建OpenCV4j.cpp，实现OpenCV4j.h定义的函数。</li>
<li>编译OpenCV4j.cpp生成libhaha.so。</li>
<li>在java虚拟机运行java程序OpenCV4j。</li>
</ul>
<h2 id="编写OpenCV4j-java"><a href="#编写OpenCV4j-java" class="headerlink" title="编写OpenCV4j.java"></a>编写OpenCV4j.java</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">OpenCV4j</span> </span>&#123;</div><div class="line">        <span class="keyword">static</span>&#123;</div><div class="line">                System.loadLibrary(<span class="string">"haha"</span>);</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">native</span> <span class="keyword">double</span> <span class="title">getVariance</span><span class="params">(String img)</span></span>;</div><div class="line"></div><div class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">double</span> <span class="title">getVarianceImg</span><span class="params">(String arg)</span> </span>&#123;</div><div class="line">                OpenCV4j cv = <span class="keyword">new</span> OpenCV4j();</div><div class="line">                <span class="keyword">return</span> cv.getVariance(arg);</div><div class="line">        &#125;</div><div class="line"></div><div class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</div><div class="line">                String imgPath = args[<span class="number">0</span>];</div><div class="line">                System.out.println(getVarianceImg(imgPath));</div><div class="line"></div><div class="line">        &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="生成OpenCV4j-h"><a href="#生成OpenCV4j-h" class="headerlink" title="生成OpenCV4j.h"></a>生成OpenCV4j.h</h2><h3 id="1-javac编译OpenCV4j-java生成OpenCV4j-class"><a href="#1-javac编译OpenCV4j-java生成OpenCV4j-class" class="headerlink" title="1) javac编译OpenCV4j.java生成OpenCV4j.class"></a>1) javac编译OpenCV4j.java生成OpenCV4j.class</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@DS-DEV-05 test]# javac OpenCV4j.java</div></pre></td></tr></table></figure>
<h3 id="2-javah生成OpenCV4j-h"><a href="#2-javah生成OpenCV4j-h" class="headerlink" title="2) javah生成OpenCV4j.h"></a>2) javah生成OpenCV4j.h</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@DS-DEV-05 test]# javah -jni OpenCV4j</div></pre></td></tr></table></figure>
<p>生成的头文件OpenCV4j.h如下：<br><figure class="highlight c++"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/* DO NOT EDIT THIS FILE - it is machine generated */</span></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;jni.h&gt;</span></span></div><div class="line"><span class="comment">/* Header for class OpenCV4j */</span></div><div class="line"></div><div class="line"><span class="meta">#<span class="meta-keyword">ifndef</span> _Included_OpenCV4j</span></div><div class="line"><span class="meta">#<span class="meta-keyword">define</span> _Included_OpenCV4j</span></div><div class="line"><span class="meta">#<span class="meta-keyword">ifdef</span> __cplusplus</span></div><div class="line"><span class="keyword">extern</span> <span class="string">"C"</span> &#123;</div><div class="line"><span class="meta">#<span class="meta-keyword">endif</span></span></div><div class="line"><span class="comment">/*</span></div><div class="line"> * Class:     OpenCV4j</div><div class="line"> * Method:    getVariance</div><div class="line"> * Signature: (Ljava/lang/String;)D</div><div class="line"> */</div><div class="line"><span class="function">JNIEXPORT jdouble JNICALL <span class="title">Java_OpenCV4j_getVariance</span></span></div><div class="line">  <span class="params">(JNIEnv *, jobject, jstring)</span>;</div><div class="line"></div><div class="line"><span class="meta">#<span class="meta-keyword">ifdef</span> __cplusplus</span></div><div class="line">&#125;</div><div class="line"><span class="meta">#<span class="meta-keyword">endif</span></span></div><div class="line"><span class="meta">#<span class="meta-keyword">endif</span></span></div></pre></td></tr></table></figure></p>
<h2 id="创建OpenCV4j-cpp"><a href="#创建OpenCV4j-cpp" class="headerlink" title="创建OpenCV4j.cpp"></a>创建OpenCV4j.cpp</h2><p>实现OpenCV4j.h定义的函数<br><figure class="highlight c"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="function">JNIEXPORT jint JNICALL <span class="title">Java_OpenCV4j_getVariance</span></span></div><div class="line">  <span class="params">(JNIEnv *, jobject, jstring)</span>;</div></pre></td></tr></table></figure></p>
<p>具体代码如下：<br><figure class="highlight c++"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div></pre></td><td class="code"><pre><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;opencv2/opencv.hpp&gt;</span></span></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"OpenCV4j.h"</span></span></div><div class="line"></div><div class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> cv;</div><div class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</div><div class="line"><span class="function">JNIEXPORT jdouble JNICALL <span class="title">Java_OpenCV4j_getVariance</span></span></div><div class="line"><span class="params">(JNIEnv * env, jobject obj, jstring path)</span></div><div class="line">&#123;</div><div class="line">        <span class="keyword">const</span> <span class="keyword">char</span> *str = (env)-&gt;GetStringUTFChars(path, <span class="number">0</span>);</div><div class="line">        Mat mat = imread( str, <span class="number">1</span> );</div><div class="line">        <span class="keyword">if</span>( !mat.data )</div><div class="line">        &#123;</div><div class="line">                <span class="keyword">return</span> <span class="number">-1</span>;</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">unsigned</span> <span class="keyword">char</span> *data;</div><div class="line">        <span class="keyword">int</span> height,width,step;</div><div class="line"></div><div class="line">        <span class="keyword">int</span> Iij;</div><div class="line"></div><div class="line">        <span class="keyword">double</span> Iave = <span class="number">0</span>, Idelta = <span class="number">0</span>;</div><div class="line"></div><div class="line">        <span class="keyword">if</span>( !mat.empty() ) &#123;</div><div class="line">                Mat gray;</div><div class="line">                Mat outGray;</div><div class="line">                <span class="comment">// 将图像转换为灰度显示</span></div><div class="line">                cvtColor(mat,gray,CV_RGB2GRAY);</div><div class="line">                <span class="comment">// 用openCV的Laplacian函数做灰度图做拉普拉斯计算，得到outGray</span></div><div class="line">                Laplacian(gray, outGray, gray.depth());</div><div class="line">                <span class="comment">//将得到的outGray转化为图片信息类IplImage</span></div><div class="line">                <span class="function">IplImage <span class="title">ipl_image</span><span class="params">(outGray)</span></span>;</div><div class="line"></div><div class="line">                data   = (uchar*)ipl_image.imageData;  <span class="comment">//图片像素信息</span></div><div class="line">                height = ipl_image.height;             <span class="comment">//图片像素高度</span></div><div class="line">                width  = ipl_image.width;              <span class="comment">//图片像素宽度</span></div><div class="line">                step   = ipl_image.widthStep;          <span class="comment">//排列的图像行大小，以字节为单位</span></div><div class="line"></div><div class="line">                <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;height;i++) &#123;    <span class="comment">//求方差</span></div><div class="line">                        <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j&lt;width;j++)</div><div class="line">                        &#123;</div><div class="line">                                Iij = (<span class="keyword">int</span>) data[i*width+j];</div><div class="line">                                Idelta = Idelta + (Iij-Iave) * (Iij-Iave);</div><div class="line">                        &#125;</div><div class="line">                &#125;</div><div class="line">                Idelta = Idelta / (width*height);</div><div class="line"></div><div class="line">        &#125;</div><div class="line">        (env)-&gt;ReleaseStringUTFChars(path, str);</div><div class="line">        <span class="keyword">return</span> Idelta;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<h2 id="编译OpenCV4j-cpp生成libhaha-so"><a href="#编译OpenCV4j-cpp生成libhaha-so" class="headerlink" title="编译OpenCV4j.cpp生成libhaha.so"></a>编译OpenCV4j.cpp生成libhaha.so</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">[root@DS-DEV-05 test]# clang -Wall -rdynamic -shared -o libhaha.so OpenCV4j.o -L/usr/local/lib -lopencv_highgui</div><div class="line">[root@DS-DEV-05 test]# ll</div><div class="line">total 120</div><div class="line">-rwxr-xr-x 1 root root 15044 Mar  3 09:59 libhaha.so</div><div class="line">-rw-r--r-- 1 root root   635 Mar  3 09:51 OpenCV4j.class</div><div class="line">-rw-r--r-- 1 root root  1271 Mar  3 09:56 OpenCV4j.cpp</div><div class="line">-rw-r--r-- 1 root root   406 Mar  3 09:52 OpenCV4j.h</div><div class="line">-rw-r--r-- 1 root root   344 Mar  3 09:02 OpenCV4j.java</div><div class="line">-rw-r--r-- 1 root root 11760 Mar  3 08:59 OpenCV4j.o</div></pre></td></tr></table></figure>
<h2 id="在java虚拟机运行java程序OpenCV4j。"><a href="#在java虚拟机运行java程序OpenCV4j。" class="headerlink" title="在java虚拟机运行java程序OpenCV4j。"></a>在java虚拟机运行java程序OpenCV4j。</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"># 需要指定java.library.path，或者直接将libhaha.so拷贝到/usr/lib，或者环境变量增加LD_LIBRARY_PATH为libhaha.so所在路径</div><div class="line">[root@DS-DEV-05 test]# java -Djava.library.path=. OpenCV4j</div><div class="line">14.0</div></pre></td></tr></table></figure>
<h2 id="踩的坑"><a href="#踩的坑" class="headerlink" title="踩的坑"></a>踩的坑</h2><ol>
<li><p>Jni中C++和Java的字符串参数传递<br>在传递图片地址字符串给C++程序的时候，Java的String和C++的string是不能对等起来的，jstring是JNI中对应于String的类型，但是和基本类型不同的是，jstring不能直接当作C++的string用。<br><a href="http://blog.csdn.net/wangkr111/article/details/7883461" target="_blank" rel="external">参考1</a><br><a href="http://www.cnblogs.com/andtt/articles/2145574.html" target="_blank" rel="external">参考2</a></p>
</li>
<li><p>编译态链接库的时候不报错，但是执行java的时候报错</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">[root@DS-DEV-05 test]# java -Djava.library.path=/usr/local/lib OpenCV4j</div><div class="line">java: symbol lookup error: /usr/local/lib/libhaha.so: undefined symbol: _ZN2cv6imreadERKSsi</div></pre></td></tr></table></figure>
</li>
</ol>
<p>这是因为编译libhaha库的时候，没有指定其所依赖的库（<a href="http://stackoverflow.com/questions/9558909/jni-symbol-lookup-error-in-shared-library-on-linux" target="_blank" rel="external">参考</a>）<br>后面加上<code>-L/usr/local/lib -lopencv_highgui</code>编译即可。</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/java/" rel="tag">#java</a>
          
            <a href="/tags/C/" rel="tag">#C++</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/12/09/common_software_install/" rel="next" title="常用软件安装">
                <i class="fa fa-chevron-left"></i> 常用软件安装
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/03/03/opencv_for_linux/" rel="prev" title="OpenCV for Linux环境">
                OpenCV for Linux环境 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="LenhartG" />
          <p class="site-author-name" itemprop="name">LenhartG</p>
          <p class="site-description motion-element" itemprop="description">美国《时代周刊》2006年度风云人物</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">38</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">14</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">25</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/gxjares" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/u/2526255830" target="_blank" title="Weibo">
                  
                    <i class="fa fa-fw fa-weibo"></i>
                  
                  Weibo
                </a>
              </span>
            
          
        </div>

        
        

        
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#java-jni调用C-语言动态链接库的具体操作步骤"><span class="nav-number">1.</span> <span class="nav-text">java jni调用C++语言动态链接库的具体操作步骤:</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#编写OpenCV4j-java"><span class="nav-number">2.</span> <span class="nav-text">编写OpenCV4j.java</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#生成OpenCV4j-h"><span class="nav-number">3.</span> <span class="nav-text">生成OpenCV4j.h</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-javac编译OpenCV4j-java生成OpenCV4j-class"><span class="nav-number">3.1.</span> <span class="nav-text">1) javac编译OpenCV4j.java生成OpenCV4j.class</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-javah生成OpenCV4j-h"><span class="nav-number">3.2.</span> <span class="nav-text">2) javah生成OpenCV4j.h</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建OpenCV4j-cpp"><span class="nav-number">4.</span> <span class="nav-text">创建OpenCV4j.cpp</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#编译OpenCV4j-cpp生成libhaha-so"><span class="nav-number">5.</span> <span class="nav-text">编译OpenCV4j.cpp生成libhaha.so</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#在java虚拟机运行java程序OpenCV4j。"><span class="nav-number">6.</span> <span class="nav-text">在java虚拟机运行java程序OpenCV4j。</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#踩的坑"><span class="nav-number">7.</span> <span class="nav-text">踩的坑</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div>
<iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="http://music.163.com/outchain/player?type=2&id=208889&auto=1&height=66"></iframe>
</div>
<div class="copyright" >
  
  &copy;  2015 - 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">LenhartG</span>
</div>

<!--
<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>
-->

<!--
<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>
-->
        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  



  




  
  

  

  

  

  


</body>
</html>
